package com.aaa;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;



@SpringBootTest
class SpringbootRedisApplicationTests02 {

    //该类中封装了很多api方法--redis服务
    @Autowired
    private RedisTemplate redisTemplate;
    @Test
    public void test01(){
        //默认redistemplate他的key和value的序列化都是使用的JdkSerializationRedisSerializer方式，该序列化要求类必须实现Serializable接口

        //我们在实际开发中，我们的key都是string类型，我们应该指定string的序列化方式
        /*redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());*/


        ValueOperations forValue = redisTemplate.opsForValue();
        forValue.set("k1",new Student(1,"李四","男"));
        System.out.println(forValue.get("k1"));

    }
}
